<?php
class Admin_Model_DefaultModuleToPage extends Zend_Db_Table{
	protected $_name = 'default_module_to_page';
	protected $_primary = array('module_code','page_code');
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	
	/*public function insertModuleToPage($data)
	{
		$adapter = $this->getDefaultAdapter();
		try {
			$adapter->beginTransaction();
			$adapter->insert('default_module_to_page', $data);
			$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}*/
	public function selectModuleBySortOrder($sort_order,$module_code,$page_code)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/defaultmoduletopage/route/selectModuleBySortOrder/module_code/".$module_code."/page_code/".$page_code."/sort_order/".$sort_order);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;
	}
	public function selectModuleByCode($code,$module)
	{//co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/defaultmoduletopage/route/selectModuleByCode/module_code/".$code."/page_code/".$module);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];	
		return $data;
	}
	/*public function deleteModuleByCode($code,$page)
	{
		$adapter = $this->getDefaultAdapter();
		try {
			$adapter->beginTransaction();
   			$where = $adapter->quoteInto("module_code = '".$code."' AND page_code = '".$page."'","");
			$adapter->delete('default_module_to_page',$where);
			$adapter->commit();
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return 1;
	}*/

	public function updateDefaultModuleToPage($sort,$module,$page)
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/defaultmoduletopage/route/updateDefaultModuleToPage/sort/".$sort."/module_code/".$module."/page_code/".$page);
		return $return->getBody();
	}
				
}